import time

from selenium import webdriver
from datetime import datetime, date, timedelta
from faker import Faker
import random

from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys

fake = Faker("zh_CN")

option = webdriver.ChromeOptions()
wd = webdriver.Chrome()

wd.get("http://172.16.60.11")
wd.maximize_window()
wd.implicitly_wait(10)

# 点击登录按钮
wd.find_element_by_xpath("//../span[text() = '用户中心登录']").click()

# 输入邮箱
wd.find_element_by_xpath("//input[@placeholder= '邮箱']").send_keys("user@forensix.cn")

# 输入密码
wd.find_element_by_xpath("//input[@placeholder = '密码']").send_keys("123456")

# 点击“授权并登录”按钮
wd.find_element_by_xpath("//span[text() = '授权并登录']").click()

time.sleep(1)
# 找到“委托登记”tab
wd.find_element_by_xpath("//li[text() = '委托登记']").click()

# 填写“委托类型”信息
jg = fake.province() + fake.city() + "公安局"# 委托机构'

wd.find_element_by_xpath("//input[@placeholder = '请输入委托单位']").send_keys(jg)
ActionChains(wd).move_by_offset(0,0).click().perform()
wd.find_element_by_xpath("//label[text() = '机构类型']").click()

# 填写“送检人登记”
# name = fake.name()
# wd.find_element_by_xpath("//input[@placeholder = '请输入送检人姓名']").send_keys(name)
# # 在下拉框中选择
# # wd.find_element_by_xpath("//span[text() = '"+name+"']").click()
# wd.find_element_by_xpath('//input[@placeholder = "请输入职务"]').send_keys("警官")
# police_id = "12345678"
# wd.find_element_by_xpath('//input[@placeholder = "请输入警官证号码"]').send_keys(police_id)
# phone = fake.phone_number()
# wd.find_element_by_xpath('//input[@placeholder = "请输入联系电话"]').send_keys(phone)
# # 在下拉框中选择已有电话
# # wd.find_element_by_xpath("//span[text() = '"+phone+"']").click()
# wd.find_element_by_xpath('//input[@placeholder = "请输入单位"]').send_keys(jg)
# wd.find_element_by_xpath('//input[@placeholder = "请输入联系地址"]').send_keys(jg)
# wd.find_element_by_xpath('//div/input[@name = "file"]').send_keys(r'C:\Users\JYJ\Desktop\图片\微信图片_20200601160942.jpg')
wd.find_element_by_xpath('//span[text()="下一步"]').click()

# 填写“委托登记”
curr_time = datetime.now()
no = datetime.strftime(curr_time, '%Y%m%d%H%M%S')
wd.find_element_by_xpath('//input[@placeholder = "请输入执法办案系统中的案件编号"]').send_keys(no)
ele = wd.find_element_by_xpath('//input[@placeholder="选择案件类型"]')
time.sleep(2)
ele.click()

# print(i)

x = "//div[@x-placement='bottom-start']//li[@class = 'el-select-dropdown__item'][{i}]"

CaseType = wd.find_element_by_xpath(x.format(i = str(random.randint(0, 30))))

ActionChains(wd).move_to_element(CaseType).click(CaseType).perform()
CaseName = fake.name() + CaseType.text + "案"
print(CaseName)

wd.find_element_by_xpath('//input[@placeholder = "请输入案件名称"]').send_keys(CaseName)

# 选择案件性质
wd.find_element_by_xpath('//input[@placeholder = "选择案件性质"]').click()
y = '//div[@x-placement="bottom-start"]//li[@class="el-select-dropdown__item"][{z}]'
y1 = y.format(z = str(random.randint(0, 9)))
time.sleep(3)
ActionChains(wd).move_to_element(ele).click(ele).perform()


# 立案时间   当前时间的前五天
t = datetime.today() + timedelta(days = -5)
# tmp = wd.find_element_by_xpath('//input[@placeholder = "请选择立案时间"]')
# tmp.send_keys(t.strftime("%Y-%m-%d %H:%M:%S"))
#
# # 调解时间  当前时间的前三天
# t = datetime.today() + timedelta(days = -3)
# wd.find_element_by_xpath('//input[@placeholder = "请选择调解时间"]').send_keys(t.strftime("%Y-%m-%d %H:%M:%S"))
#
#
# # 发案时间   当前时间的前十天
# t = datetime.today() + timedelta(days = -10)
# wd.find_element_by_xpath('//input[@placeholder = "请选择发案时间"]').send_keys(t.strftime("%Y-%m-%d %H:%M:%S"))
#
#
# # 受理时间   当前时间
# t = datetime.today()
# wd.find_element_by_xpath('//input[@placeholder = "请选择受理时间"]').send_keys(t.strftime("%Y-%m-%d %H:%M:%S"))


# 随意点击一个元素，将选择时间的弹框去掉
# ActionChains(wd).move_by_offset(0, 0).click().perform()
# ele = wd.find_element_by_xpath("//div[@x-placement = 'top-start']//button[@class='el-button el-picker-panel__link-btn el-button--default el-button--mini is-plain']")
# ActionChains(wd).move_to_element(ele).click(ele).perform()


# 案情摘要
# wd.find_element_by_xpath('//textarea[@placeholder = "请输入案情摘要"]').send_keys("案情摘要案情摘要")


# 委托项目
x = "//div[@class='el-form-item is-required el-form-item--large']//div[@class='el-checkbox-group']//label[@class='el-checkbox'][{p}]//span[@class = 'el-checkbox__inner']"
x1 = x.format(p = str(random.randint(0, 15)))
wd.find_element_by_xpath(x1).click()

# 相关人员
# 嫌疑人
# wd.find_element_by_xpath('//span[text()="嫌疑人"]').click()
# # 涉案人
# wd.find_element_by_xpath('//span[text()="涉案人"]').click()
#
# xyname = fake.name()
# wd.find_element_by_xpath('//input[@placeholder="请输入嫌疑人姓名"]').send_keys(xyname)
# wd.find_element_by_xpath('//li/span[text()="'+xyname+'"]').click()
#
# sname = fake.name()
# wd.find_element_by_xpath('//input[@placeholder="请输入涉案人姓名"]').send_keys(sname)
# wd.find_element_by_xpath('//li/span[text()="'+sname+'"]').click()


# 点击下一步按钮
wd.find_element_by_xpath('//div[@class="step step-two"]//button/span[text()="下一步"]').click()


# 委托备注
# wd.find_element_by_xpath('//div[@class="step step-three"]//input[@placeholder="请输入本次委托的其他说明，备注等信息"]').\
#     send_keys("我是委托备注我是委托备注我是委托备注我是委托备注我是委托备注我是委托备注")

wd.find_element_by_xpath('//div[@class="step step-three"]//span[text()="提交"]').click()


# 查看案件
wd.find_element_by_xpath('//span[text()="查看案件"]').click()





# 创建检材
wd.find_element(By.ID,'tab-evidence').click()
time.sleep(1)
# 点击添加检材按钮
wd.find_element(By.XPATH,'//button[@class="el-button f-m-t-20 el-button--primary"]').click()

time.sleep(1)
types = wd.find_elements(By.XPATH,'//div[@class="type-list"]/div')
print(len(types))
lens = len(types)
# for i in range(lens):
#     x = str(i)
x = str(1)
wd.find_element(By.XPATH,'//div[@class="type-list"]/div["'+x+'"]').click()
wd.find_element(By.XPATH,'//div[@class="el-dialog__body"]//div[@class="f-tac f-m-t-20"]//span[text()="下一步"]').click()
wd.find_element(By.XPATH,'//div[@class="el-upload el-upload--picture-card"]/input').send_keys(r'C:\Users\JYJ\Desktop\图片\sample_back.jpg')
wd.find_element(By.XPATH, '//div[@class="el-upload el-upload--picture-card"]/input').send_keys(r'C:\Users\JYJ\Desktop\图片\sample_front.jpg')
wd.find_element(By.XPATH,'//div[@class="f-tac"]//button[@class="el-button el-button--primary"]').click()
time.sleep(1)
wd.find_element(By.XPATH,'//span[text()="提交"]/..').click()
#  wd.find_element(By.XPATH,'//span[text()="继续添加检材"]').click()

# 检材添加完成
wd.find_element(By.XPATH,'//span[text()="添加完成"]').click()
# wd.find_element_by_xpath("//span[@class= 'f-fs-16 f-m-r-10']").click()
# time.sleep(1)
# wd.find_element_by_xpath("//div[@title = '登出']").click()
# wd.find_element_by_xpath("//../span[text() = '用户中心登录']").click()
# wd.find_element_by_link_text("账号密码登录").click()
#
#
# # 输入邮箱
# wd.find_element_by_xpath("//input[@placeholder= '邮箱']").send_keys("admin@forensix.cn")
# # 输入密码
# wd.find_element_by_xpath("//input[@placeholder = '密码']").send_keys("123456")
# # 点击“授权并登录”按钮
# wd.find_element_by_xpath("//span[text() = '授权并登录']").click()
#
#
# # 跳转到委托评审页面
# wd.find_element(By.XPATH,'//li/span[text()="委托评审"]').click()
#
# # 查找用户创建的案件
# ele = wd.find_element(By.XPATH,'//input[@placeholder="姓名/编号/名称/委托单位/标签"]')
# ActionChains(wd).move_to_element(ele).send_keys(CaseName).send_keys(Keys.ENTER).perform()



time.sleep(10)
wd.close()











